<template>
    <div>
        <h2>合同详情</h2>
        <pre>{{ contractContent }}</pre>
        <button @click="downloadContract">下载合同</button>
        <router-link to="/">返回首页</router-link>
    </div>
</template>

<script>
export default {
    data() {
        return {
            contractContent: ''
        };
    },
    created() {
        const content = this.$route.query.content;
        this.contractContent = content || '';
    },
    methods: {
        downloadContract() {
            if (!this.contractContent) return;

            const packageName = this.$route.query.packageName || 'contract';
            const blob = new Blob([this.contractContent], { type: 'text/plain' });
            const url = URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.download = `contract_${packageName}.txt`;
            a.click();
            URL.revokeObjectURL(url);
        }
    }
};
</script>